package edu.mse.camel.client.whiteboard.gef.ui.properties;

import java.util.List;

import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;

import edu.mse.camel.client.whiteboard.gef.whiteboard.Connection;

public class ConnectionPropertySource extends AbstractPropertySource {
	
	private static final String ID_STYLE = "Line Style";
	private static final Integer DASHED = new Integer(0);
	private static final Integer SOLID = new Integer(1);
	
	public ConnectionPropertySource(Object model) {
		super(model);
	}
	
	private Connection getConnectionModel() {
		return (Connection) getModel();
	}
	
	public void createPropertyDescriptors(List descriptors) {
		String values[] = {"Dashed", "Solid"};
		descriptors.add(new ComboBoxPropertyDescriptor(
				ID_STYLE,
				ID_STYLE,
				values));
	}
	
	public Object getPropertyValue(Object id) {
		if(id == ID_STYLE) {
			if(getConnectionModel().isDashed()) {
				return DASHED;
			} else {
				return SOLID;
			}
		}
		return null;
	}
	
	public boolean isPropertySet(Object id) {
		return true;
	}
	
	public void setPropertyValue(Object id, Object value) {
		if(value == null) return;
		if(id == ID_STYLE) {
			Integer intValue = (Integer) value;
			switch(intValue.intValue()) {
			case 0:
				getConnectionModel().setDashed(true);
				break;
			case 1:
				getConnectionModel().setDashed(false);
				break;
			}
		}	
	}
	
}
